package leetcode.dfs;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: https://leetcode.cn/problems/subsets/
 * @Author Ammar
 * @Create 2023/8/3 12:44
 */
public class _78_子集 {
    List<List<Integer>> res = new ArrayList<>();
    int n;
    public List<List<Integer>> subsets(int[] nums) {
        n = nums.length;
        for (int k = 0; k <= n; k++) {
            dfs(0, k, new ArrayList<>(), nums);
        }
        return res;
    }
    
    
    public void dfs(int start, int k, List<Integer> cur, int[] nums) {
        if (k == 0) {
            res.add(new ArrayList<>(cur));
            return;
        }

        for (int i = start; i < n; i++) {
            cur.add(nums[i]);
            dfs(i + 1, k - 1, cur, nums);
            cur.remove(cur.size() - 1);
        }
    }
}
